﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using WEBDT.Base;
using WEBDT.ViewModel;
namespace WEBDT.Areas.Admin.Controllers
{
    public class LoaiTTController : BaseController<LoaiTT>
    {
        //
        // GET: /Admin/LoaiTT/

        public ActionResult Index()
        {
            return View();
        }
        [HttpGet]
        public override ActionResult insert()
        {
            var model = new LoaiTTModel
            {
                tontai = false,
            };

            return View(model);
        }

        [HttpPost]
        public override ActionResult insert(FormCollection fr)
        {
            var ht = new LoaiTTModel
            {
                TenLoai = fr.Get("tenloai"),
            };
            var model = new LoaiTT
            {
                TenLoai = ht.TenLoai,
            };
            repository.Insert<LoaiTT>(model);
            return RedirectToAction("getAll");
        }

        [HttpGet]
        public override ActionResult update(int id)
        {
            var model = repository.SelectByID<LoaiTT>(id);
            var ht = new LoaiTTModel
            {
                MaLoai = model.MaLoai,
                TenLoai =  model.TenLoai,
            };
            return View(ht);
        }

        [HttpPost]
        public override ActionResult update(FormCollection fr)
        {
            var ht = new LoaiTTModel
            {
                MaLoai = Convert.ToInt32(fr.Get("maloai")),
                TenLoai = fr.Get("tenloai"),
            };

            var model = repository.SelectByID<LoaiTT>(ht.MaLoai);
            model.TenLoai = ht.TenLoai;
            repository.commitchanges();
            return RedirectToAction("getAll");
        }
    }
}
